package cn.zktr.Personnel.common;

import java.security.MessageDigest;
 
public class Md5Encode {
	
	private final static String[] digits = {"0", "1", "2", "3", "4", "5", "6", "7","8", "9", "a", "b", "c", "d", "e", "f"};
	
	public String MD5Encode(String param) {
        String result = "";
        try {
        result = param;
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(result.getBytes("UTF-8"));
            result = byteArrayToHexString(md.digest());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
	
	public String byteArrayToHexString(byte[] b) {
        StringBuffer sb = new StringBuffer();
        for (byte aB : b) {
            sb.append(byteToHexString(aB));
        }
        return sb.toString();
    }
	
	private String byteToHexString(byte b) {
        int n = b;
        if (n < 0) {
            n = 256 + n;
        }
        int d1 = n / 16;
        int d2 = n % 16;
        return digits[d1] + digits[d2];
    }
}
